﻿package com.tudou.newPlayer
{
    import com.tudou.model.*;
    import com.tudou.v2.*;
    import flash.display.*;

    public class TudouPlayer extends Sprite
    {
        protected var _debugURL:String;
        protected var metaDataMap:Array;
        protected var _status:int;
        protected var _rateType:int;
        protected var _iBaseInfo:IBaseInfo;
        protected var _videoInfo:VideoInfo;
        protected var player:BaseTudouPlayer;

        public function TudouPlayer(param1:uint = 400, param2:uint = 300)
        {
            player = new BaseTudouPlayer(param1, param2);
            addChild(player);
            metaDataMap = [];
            player.addEventListener(PlayerEvent.CHANGE_VIDEO_STATUS, statusChangeHlr);
            player.addEventListener(PlayerEvent.RECEIVE_METADATA, metaDataHlr);
            return;
        }// end function

        public function setSkipHeadTailValue(param1:Number, param2:Number, param3:Number) : void
        {
            player.setSkipHeadTailValue(param1, param2, param3);
            return;
        }// end function

        public function togglePause() : void
        {
            player.togglePause();
            return;
        }// end function

        public function pause() : void
        {
            player.pause();
            return;
        }// end function

        override public function set width(param1:Number) : void
        {
            player.width = param1;
            return;
        }// end function

        public function get videoScale() : Number
        {
            return player.videoScale;
        }// end function

        public function set videoInfo(param1:VideoInfo) : void
        {
            _videoInfo = param1;
            player.setMasks(_videoInfo.logoMaskList);
            nextStep();
            return;
        }// end function

        public function get mustHasStartLoad() : Boolean
        {
            return _status >= VideoStatus.LOADING;
        }// end function

        override public function set scaleX(param1:Number) : void
        {
            player.scaleX = param1;
            return;
        }// end function

        override public function set scaleY(param1:Number) : void
        {
            player.scaleY = param1;
            return;
        }// end function

        protected function metaDataHlr(event:PlayerEvent) : void
        {
            currMetaData = player.metaData;
            return;
        }// end function

        public function get mute() : Boolean
        {
            return player.mute;
        }// end function

        protected function get currMetaData() : MetaData
        {
            return metaDataMap[_rateType];
        }// end function

        public function get orginalVideoScale() : Number
        {
            return player.orginalVideoScale;
        }// end function

        public function set videoScale(param1:Number) : void
        {
            player.videoScale = param1;
            return;
        }// end function

        override public function get height() : Number
        {
            return player.height;
        }// end function

        public function set aimSeekValue(param1:Number) : void
        {
            player.aimSeekValue = param1;
            return;
        }// end function

        public function resume() : void
        {
            player.resume();
            return;
        }// end function

        public function setBackground(param1:uint, param2:Number) : void
        {
            player.setBackground(param1, param2);
            return;
        }// end function

        public function set brightness(param1:Number) : void
        {
            player.brightness = param1;
            return;
        }// end function

        public function set volume(param1:Number) : void
        {
            player.volume = param1;
            return;
        }// end function

        public function get rotateType() : int
        {
            return player.rotateType;
        }// end function

        public function set debugURL(param1:String) : void
        {
            _debugURL = param1;
            return;
        }// end function

        public function set mute(param1:Boolean) : void
        {
            player.mute = param1;
            return;
        }// end function

        public function get playerStatus() : IPlayerStatus
        {
            return player;
        }// end function

        public function play() : void
        {
            load();
            if (mustHasStartPlay)
            {
                return;
            }
            _status = VideoStatus.LOAD_TO_PLAY;
            nextStep();
            return;
        }// end function

        public function get volume() : Number
        {
            return player.volume;
        }// end function

        protected function errorHlr() : void
        {
            _videoInfo.next(_rateType);
            var _loc_1:* = currVideoNodeInfo;
            if (_debugURL)
            {
                _loc_1.url = _debugURL;
            }
            player.retry(_loc_1.url);
            player.bandCtrl = _loc_1.bandCtrl;
            return;
        }// end function

        protected function set currMetaData(param1:MetaData) : void
        {
            metaDataMap[_rateType] = param1;
            return;
        }// end function

        protected function statusChangeHlr(event:PlayerEvent) : void
        {
            var _loc_2:* = player.videoStatus.status;
            switch(_loc_2)
            {
                case VideoStatus.ERROR:
                {
                    errorHlr();
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        override public function get width() : Number
        {
            return player.width;
        }// end function

        override public function set height(param1:Number) : void
        {
            player.height = param1;
            return;
        }// end function

        public function reset() : void
        {
            metaDataMap = [];
            _videoInfo = null;
            _status = VideoStatus.INITED;
            player.reset();
            return;
        }// end function

        public function set iBaseInfo(param1:IBaseInfo) : void
        {
            _iBaseInfo = param1;
            player.iBaseInfo = param1;
            return;
        }// end function

        public function get brightness() : Number
        {
            return player.brightness;
        }// end function

        public function set fullFillVideo(param1:Boolean) : void
        {
            player.fullFillVideo = param1;
            return;
        }// end function

        override public function get scaleX() : Number
        {
            return player.scaleX;
        }// end function

        override public function get scaleY() : Number
        {
            return player.scaleY;
        }// end function

        public function set alwaysCheckPolicyFile(param1:Boolean) : void
        {
            player.alwaysCheckPolicyFile = param1;
            return;
        }// end function

        protected function nextStep() : void
        {
            if (_videoInfo == null || !mustHasStartLoad)
            {
                return;
            }
            var _loc_1:* = currVideoNodeInfo;
            if (!player.hasLoading)
            {
                if (_debugURL)
                {
                    _loc_1.url = _debugURL;
                }
                player.load(_loc_1.url);
                player.bandCtrl = _loc_1.bandCtrl;
            }
            if (mustHasStartPlay)
            {
                player.play();
            }
            return;
        }// end function

        protected function get currVideoNodeInfo() : VideoNodeInfo
        {
            return _videoInfo.getCurrVideoNodeInfo(_rateType);
        }// end function

        public function get mustHasStartPlay() : Boolean
        {
            return _status >= VideoStatus.LOAD_TO_PLAY;
        }// end function

        public function load() : void
        {
            if (mustHasStartLoad)
            {
                return;
            }
            _status = VideoStatus.LOADING;
            nextStep();
            return;
        }// end function

        public function replay() : void
        {
            player.replay();
            return;
        }// end function

        public function get fullFillVideo() : Boolean
        {
            return player.fullFillVideo;
        }// end function

        public function set rotateType(param1:int) : void
        {
            player.rotateType = param1;
            return;
        }// end function

        public function get alwaysCheckPolicyFile() : Boolean
        {
            return player.alwaysCheckPolicyFile;
        }// end function

        public function set rateType(param1:int) : void
        {
            _rateType = param1;
            if (player.playTimePos > 0)
            {
                player.aimSeekValue = player.playTimePos;
            }
            if (_videoInfo == null || !mustHasStartLoad)
            {
                return;
            }
            var _loc_2:* = currVideoNodeInfo;
            if (_debugURL)
            {
                _loc_2.url = _debugURL;
            }
            if (player.isError)
            {
                player.retry(_loc_2.url);
            }
            else
            {
                player.reLoadPlay(_loc_2.url, currMetaData);
            }
            player.bandCtrl = _loc_2.bandCtrl;
            return;
        }// end function

        override public function set filters(param1:Array) : void
        {
            player.filters = param1;
            return;
        }// end function

        public function seek(param1:Number, param2:Boolean = false, param3:Number = 0) : void
        {
            if (currMetaData == null)
            {
                player.aimSeekValue = param1;
            }
            else
            {
                player.seekPercent(param1, param2, param3);
            }
            return;
        }// end function

        override public function get filters() : Array
        {
            return player.filters;
        }// end function

        public function close() : void
        {
            metaDataMap = [];
            _videoInfo = null;
            player.close();
            return;
        }// end function

    }
}
